/**
 *
 * @author siuming
 *
 */


import com.zytech.modules.lang.Langs
import com.zytech.zspider.core.TaskDefinition
import com.zytech.zspider.core.TaskResult

/**
 *
 * @param name
 * @param url
 * @param method
 * @param params
 * @param headers
 * @param props
 * @return
 */
def __ofTask(name, url, method = 'GET', params = [:], headers = [:], props = [:]) {
    TaskDefinition.of(name, url, method).params(params).headers(headers).settings(props)
}

/**
 *
 * @param millis
 * @return
 */
def __sleep(millis) {
    Langs.sleepQuietly(millis)
}

/**
 *
 * @param result
 * @param values
 * @return
 */
def __reset_result_values(result, values = [:]) {
    TaskResult
            .ofBuilder()
            .taskname(result.getTaskname())
            .values(values)
            .startTime(result.getStartTime())
            .elapsedTime(result.getElapsedTime())
            .build();
}

/**
 *
 * @param candidate
 * @param keymap
 * @return
 */
def __keys_replace(candidate, keymap) {
    candidate.collectEntries {
        if (null != keymap[it.key]) {
            return [keymap[it.key], it.value]
        }
        it;
    }
}